<template>
  <section class="testimonials-section">
    <div class="container">
      <div class="section-header">
        <h2>用户评价</h2>
        <p>看看其他用户怎么说</p>
      </div>

      <div class="testimonials-carousel">
        <div
          class="testimonial-track"
          :style="{ transform: `translateX(-${currentTestimonial * 100}%)` }"
        >
          <div v-for="testimonial in testimonials" :key="testimonial.id" class="testimonial-card">
            <div class="testimonial-content">
              <div class="quote-icon">
                <i class="icon-quote"></i>
              </div>
              <p class="testimonial-text">{{ testimonial.content }}</p>
            </div>

            <div class="testimonial-author">
              <!-- 用户头像占位符 -->
              <div class="author-avatar-placeholder">
                <i class="icon-user"></i>
              </div>
              <div class="author-info">
                <div class="author-name">{{ testimonial.author }}</div>
                <div class="author-role">{{ testimonial.role }}</div>
              </div>
              <div class="testimonial-rating">
                <div class="stars">
                  <i
                    v-for="i in 5"
                    :key="i"
                    class="icon-star"
                    :class="{ filled: i <= testimonial.rating }"
                  ></i>
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- 导航点 -->
        <div class="testimonial-dots">
          <button
            v-for="(testimonial, index) in testimonials"
            :key="testimonial.id"
            class="dot"
            :class="{ active: index === currentTestimonial }"
            @click="currentTestimonial = index"
          ></button>
        </div>
      </div>
    </div>
  </section>
</template>

<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'

const currentTestimonial = ref(0)
// 修复：将 NodeJS.Timeout 改为 number
let autoPlayTimer: number | null = null

// 用户评价数据
const testimonials = [
  {
    id: 1,
    content: '通过AI剧场的商务谈判训练，我的沟通技巧得到了显著提升，在实际工作中更加自信了。',
    author: '张经理',
    role: '销售总监',
    rating: 5,
  },
  {
    id: 2,
    content: '面试培训模块太棒了！帮我成功拿到了心仪的工作机会，AI的反馈非常专业。',
    author: '李同学',
    role: '应届毕业生',
    rating: 5,
  },
  {
    id: 3,
    content: '作为培训师，我经常使用这个平台来提升自己的教学技巧，效果非常显著。',
    author: '王老师',
    role: '企业培训师',
    rating: 4,
  },
]

// 自动播放
const nextSlide = () => {
  currentTestimonial.value = (currentTestimonial.value + 1) % testimonials.length
}

const startAutoPlay = () => {
  autoPlayTimer = setInterval(nextSlide, 4000)
}

const stopAutoPlay = () => {
  if (autoPlayTimer) {
    clearInterval(autoPlayTimer)
    autoPlayTimer = null
  }
}

onMounted(() => {
  startAutoPlay()
})

onUnmounted(() => {
  stopAutoPlay()
})
</script>

<style scoped>
.testimonials-section {
  background: #f8fafc;
  display: flex;
  align-items: center;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  width: 100%;
}

.section-header {
  text-align: center;
  margin-bottom: 3rem;
}

.section-header h2 {
  font-size: 2.5rem;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 0.5rem;
}

.section-header p {
  font-size: 1rem;
  color: #6b7280;
  margin: 0;
}

.testimonials-carousel {
  position: relative;
  max-width: 900px;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 0.75rem;
}

.testimonial-track {
  display: flex;
  transition: transform 0.5s ease-out;
}

.testimonial-card {
  width: 100%;
  flex-shrink: 0;
  background: white;
  padding: 2.5rem;
  box-sizing: border-box;
  border-radius: 0.75rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.testimonial-content {
  text-align: center;
  margin-bottom: 2rem;
}

.quote-icon {
  font-size: 2rem;
  color: #3b82f6;
  margin-bottom: 1.5rem;
}

.icon-quote::before {
  content: '"';
  font-family: Georgia, serif;
}

.testimonial-text {
  font-size: 1.125rem;
  line-height: 1.6;
  color: #1e293b;
  font-style: italic;
  margin: 0;
}

.testimonial-author {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  /* 移除了 justify-content: center，改为左对齐 */
}

.author-avatar-placeholder {
  width: 60px;
  height: 60px;
  background: rgba(59, 130, 246, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #3b82f6;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.icon-user::before {
  content: '👤';
}

.author-info {
  flex: 1;
  /* 移除了 text-align: center */
}

.author-name {
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: #1f2937;
}

.author-role {
  font-size: 0.875rem;
  color: #64748b;
}

.testimonial-rating {
  flex-shrink: 0;
}

.stars {
  display: flex;
  gap: 2px;
}

.icon-star {
  color: #f1f5f9;
  font-size: 1rem;
}

.icon-star.filled {
  color: #f59e0b;
}

.icon-star::before {
  content: '★';
}

.testimonial-dots {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: none;
  background: #f1f5f9;
  cursor: pointer;
  transition: all 0.3s ease-out;
  padding: 0;
}

.dot.active {
  background: #3b82f6;
}

@media (max-width: 768px) {
  .testimonials-section {
    padding: 3rem 0;
  }

  .container {
    padding: 0 1rem;
  }

  .section-header h2 {
    font-size: 2rem;
  }

  .testimonial-card {
    padding: 2rem;
  }

  .testimonial-text {
    font-size: 1rem;
  }

  .testimonial-author {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .author-info {
    text-align: center;
  }
}

@media (max-width: 576px) {
  .testimonial-card {
    padding: 1.5rem;
  }

  .author-avatar-placeholder {
    width: 50px;
    height: 50px;
    font-size: 1rem;
  }
}
</style>
